// pages/clbj/clbj.js
var t = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bj:0,
    cc:0,
    user:[],
    leftid:0,
    scanReachBottom: false,
    tab:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('options',options)
    if (options.tab == 1){
      this.setData({
        cc: options.tab,
        tab: options.tab
      })
    }
   
    var that = this
      that.fangfa()
    
  },
  br:function(){
    wx.switchTab({
      url: '../index/index',
    })
  },
  bj:function(e){
    var ss = this
    var y = e.currentTarget.dataset.cc
    ss.setData({
      cc:y,
     user:[],
      leftid:0,
      scanReachBottom:false
    });
    if (!ss.data.scanReachBottom){
      ss.fangfa()
    }
   
  },
  fangfa:function(){
    var ss = this
    if (ss.data.cc == 1) {
      t.util.request({
        url: "entry/wxapp/Api",
        data: {
          m: "monai_market",
          r: "extends.obtainOffer",
          uid: wx.getStorageSync("uid"),
          leftid: ss.data.leftid += 1
        },
        success: (tt) => {
          var tt = tt.data
          console.log(tt)
          if (tt.errno == 0) {
            if(tt.data.length < 10){
              ss.setData({
                scanReachBottom: true,
              })
            }
            ss.setData({
              user:ss.data.user.concat(tt.data),
              bj: 1
            })
          } else {
            wx.showToast({
              title: tt.message,
              icon: "none",
              duration: 2000
            })
          }
        }
      });
    } else {
      t.util.request({
        url: "entry/wxapp/Api",
        data: {
          m: "monai_market",
          r: "extends.myoffer",
          uid: wx.getStorageSync("uid"),
          leftid: ss.data.leftid += 1
        },
        success: (tt) => {
          var tt = tt.data
          console.log(tt)
          if (tt.errno == 0) {
            if (tt.data.length < 10) {
              ss.setData({
                scanReachBottom: true,
              })
            }
            ss.setData({
              user: ss.data.user.concat(tt.data),
              bj: 0
            })
          } else {
            wx.showToast({
              title: tt.message,
              icon: "none",
              duration: 2000
            })
          }
        }
      });
    }
  },
  shuaxin:function(){
    console.log('123123')
    if (!this.data.scanReachBottom) {
      this.fangfa()
    }
   
  },
  bohao:function(e){
    var t = this
    var phone = e.currentTarget.dataset.phone
    wx.makePhoneCall({
      phoneNumber: phone
    })
  },
  tz:function(e){
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../home/carMessage/carMessage?id=' + id,
    })
  }
})